<%@ page import="photobox.account.User" %>
<g:render template="../home/header" ></g:render>
<script>

    var tipMessage= function (msg,url) {
        if(confirm(msg)){
            window.location.href=url;
        }
        return false;
    }

    var ajaxOrder = function(max,offset){
        if($("#maxId").attr("name")){
            return;
        }
        $("#maxId").attr("name",'request')
        $.ajax({
            type:"POST",
            url:"<g:createLink controller='order' action='order'/>",
            data:{max:max,offset:offset,json:1},
            dataType:'json',
            beforeSend:function(){
            },
            success:function(data){
                $("#maxId").attr("name","");
                $('#maxId').val(data.max);
                $('#offsetId').val(data.offset);
                var d = data.orders;
                var n = d.length;
                if(n == 0 && data.offset<=8){
                    $(".table1").html("您还未提交过任何订单").attr("style","color:red;margin-left:26px;");
                }
                var j = 0;
                var num = (data.offset == data.max) ? 1 : (data.offset - data.max + 1);

                for(var i = 0 ; i < n ; i++){
                    $("#orderList").each(function() {

                        if (d[j]) {
                            var r = d[j]
                            var html = [];
                            var str1= r.dateCreated.replace(/Z/, "");
                            var str2 = str1.replace(/T/, " ");
                            if(i%2 == 0){
                                html.push('<tr><td>' + str2 + '</td>');
                            }else {
                                html.push('<tr class="bgf2"><td>'+ str2 +'</td>');
                            }
                            //html.push('<td width="15%"><a href="#">订单编号</a></td>');
                            html.push('<td><a href="/photobox/order/orderItems?orderId='+ r.id +'" style="width:100%;">'+ r.id +'</a></td>');
                            html.push('<td><a href="/photobox/order/orderItems?orderId='+ r.id +'" style="width:100%;"><p>'+ r.photoName+'</p></a></td>');
                                html.push('<td class="orange">￥'+ r.totalPrice +'</td>');
                            var stateCN="";
                            var stateStr="";
                            switch(r.orderStatus){
                                case 10:
                                    stateCN="未付款";
                                    stateStr='<a href="/photobox/order/proceedPay?orderId='+ r.id +' " class="annui annui2">付 款</a>';
                                    break;
                                case 20:
                                    stateCN="已付款";
                                    break
                                case 30:
                                    stateCN="制作中";
                                    break
                                case 40:
                                    stateCN="已发货";
                                    var str = '/photobox/order/receiveConfirmation?orderId='+ r.id;
                                        var msg = "确认收到货物后再执行确认收货操作，以防钱货两空！"
                                    stateStr='<a href="javascript:;" onclick="tipMessage(\''+msg+'\',\''+str+'\') " class="annui annui1">确认收货</a>';
                                    break
                                case 50:
                                    stateCN="已收货";
                                    break
                            }
                            html.push('<td  style="text-align: center;">'+ stateCN +'</td>');
                            html.push('<td >'+stateStr+'<tr>');
                            $(this).append(html.join(' '));
                            j++;
                            num++;
                        }else{
                            $("#maxId").attr("name","request");
                        }
                    });
                }
            },
            error: function (data, status, e)//服务器响应失败处理函数
            {
                alert(e+'没有发现');
            }
        });
    }
    $(document).ready(function(){
        //初始化数据
        ajaxOrder(8,0);
        $(window).scroll(function(){

            // 被卷去的高度
            var scrollTop = document.body.scrollTop||document.documentElement.scrollTop;
            // 页面高度
            var pageHeight = $(document).height();
            // 可视区域高度
            var viewHeight = $(window).height();
            //alert(viewHeight);
            //当滚动到底部时
            if((scrollTop+viewHeight)>(pageHeight-20)){
                ajaxOrder($('#maxId').val(),$('#offsetId').val());
            }
        });
    });
</script>
<!--主体-->
<div class="wid_1200 mTo_20">
    <div class="f_l">
        <div class="left_blk mBo_20 load_blk_ying">
            <div class="user_blk"><g:if test="${session.userId}">
                <div class="user_head"><!--<div class="user_head"><img src="../${user?.photoImage}" alt="头像"></div>-->
                    <g:if test="${photobox.account.User.get(session.userId)?.photoImage}">
                        <img src="../${User.findById(session.userId)?.photoImage}"  alt="头像" />
                    </g:if>
                    <g:else>
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown"><img src="${resource(dir: '/assets/img', file: 'headp_140.jpg')}" alt="photobox" class="userPic"></a>
                    </g:else>
                </div>
            </g:if></div>
            <!--nav-->
            <div class="nav_left bor4" style=" height:108px;">
                <ul class="">
                    <li><g:link controller="member" action="browserHistory"><span class=" tubiao4 tubiao4_1">&nbsp;</span>我浏览的作品</g:link></li>
                    <li><g:link controller="member" action="purchasedPhoto"><span class=" tubiao4 tubiao4_2">&nbsp;</span>我购买的作品</g:link></li>
                </ul>
            </div>
            <!--/nav-->
        </div>
        <!--/用户简介-->
        <div class="left_blk pBo_20">
            <div class="sJiao"><div class="jiao1"></div></div>
            <div class="user_jianj">
                <p>${User.findById(session.userId)?.presentation}</p>
            </div>
        </div>
        <!--/用户简介-->
        <div class="kong_100 clear"></div>
    </div>

    <!--blk3-->
    <div class="blk3 f_r load_blk_ying bor1 load1">
        <!--我购买的作品-->
        <div class="crumbs mLe_20">
            <span>个人信息</span><em class="tubiao2">&nbsp;</em><span>我的订单</span>
        </div>
        <!---->
        <div class="blk3_1 mTo_20">
            <div class="table_qu">
                <input type="hidden" value="${max}" id="maxId" />
                <input type="hidden" value="${offset}" id="offsetId" />
                <table class="table1" width="100%">
                    <thead>
                    <tr>
                        <th width="15%">下单时间</th>
                        <th width="15%">订单编号</th>
                        <th width="20%">作品名称</th>

                        <th width="12%">订单价格</th>
                        <th width="12%">订单状态</th>
                        <th width="12%">操作</th>
                    </tr>
                    </thead>
                    <tbody id="orderList">

                    <!--
                    <tr>
                        <td>2013-09-11  19：36</td>
                        <td width="15%"><a href="/photobox/order/orderItems">111122223333444</a></td>
                        <td><a href="/photobox/order/orderItems"><p>作品名称作品名称作品名称作品名称作品名称</p></a></td>
                        <td class="orange">￥360.00</td>
                        <td>等待付款</td>
                        <td><a href="javascript:;" class="annui annui2">付款</a></td>
                    </tr>
                    <tr class="bgf2">
                        <td>2013-09-11  19：36</td>
                        <td width="15%"><a href="/photobox/order/orderItems">111122223333444</a></td>
                        <td><a href="/photobox/order/orderItems"><p>作品名称作品名称作品名称作品名称作品名称</p></a></td>
                        <td class="orange">￥360.00</td>
                        <td>进行中</td>
                        <td><a href="javascript:;" class="annui annui1">确认收货</a></td>
                    </tr>
                    -->
                    </tbody>
                </table>
            </div>
        </div>
        %{--<div class="bottomBor"></div>--}%%{--遮住底部阴影--}%
    </div>
    <!--/blk3-->


</div>
<!--/主体-->

<g:render template="../home/footer" ></g:render>


